<template>
<div>
  <el-dialog title="提交审批结果"
    :visible.sync="visible"
    :close-on-click-modal="false"
    class="edit-form"
    @close="$emit('update:approvalEquipmentSubmitFormShow', false)"
  >
   <el-form :model="editForm" label-width="180px" ref="editForm">
   <el-tag>基本信息</el-tag>
	 <el-form-item label="序号">
	   <el-input v-model="editForm.squence" :disabled="true"></el-input>
	 </el-form-item>
	  <el-form-item label="申请单位名称">
		  <el-input v-model="editForm.applicant_name" placeholder="申请单位名称" :disabled="true"></el-input>
		</el-form-item>
		<el-form-item label="申请单位地址">
		  <el-input v-model="editForm.applicant_addres" placeholder="申请单位地址" :disabled="true"></el-input>
		</el-form-item>
	  <el-form-item label="单位联系人" prop="unit_contact">
		<el-input v-model="editForm.unit_contact" :disabled="true"></el-input>
	  </el-form-item>
	  <el-form-item label="联系电话" prop="telephone">
		<el-input v-model="editForm.telephone" :disabled="true"></el-input>
	  </el-form-item>
	  <el-form-item label="E-mail" prop="E_mail">
		<el-input v-model="editForm.E_mail" :disabled="true"></el-input>
	  </el-form-item>
	  <el-form-item label="业务系统名称" prop="business_system_name">
		<el-input v-model="editForm.business_system_name" :disabled="true"></el-input>
	  </el-form-item>
	  <el-form-item label="接口人/电话" prop="interface_tel">
		<el-input v-model="editForm.interface_tel" :disabled="true"></el-input>
	  </el-form-item>

	 <el-tag>设备托管</el-tag>

	  <el-form-item label="网络需求" prop="network_requirements">
		<el-input v-model="editForm.network_requirements" :disabled="true"></el-input>
	  </el-form-item>
	  <el-form-item label="防火墙策略（源/目的IP/端口、协议）" prop="firewall_policy">
		<el-input v-model="editForm.firewall_policy" :disabled="true"></el-input>
	  </el-form-item>
	  <el-form-item label="备注" prop="remarks1">
	  		<el-input v-model="editForm.remarks1" :disabled="true"></el-input>
	  </el-form-item>
	  
	  <el-tag>开通情况反馈</el-tag>
	  <el-form-item v-if="editForm.current_link=='待开通'" label="设备型号" prop="equipment_model">
	  	<el-input v-model="editForm.equipment_model" placeholder="请输入物理机设备型号"></el-input>
	  </el-form-item>
	  <el-form-item v-if="editForm.current_link=='待开通'" label="CPU" prop="CPU">
	  	<el-input v-model="editForm.CPU" placeholder="请输入CPU信息"></el-input>
	  </el-form-item>
	  <el-form-item v-if="editForm.current_link=='待开通'" label="内存" prop="memory">
	  	<el-input v-model="editForm.memory" placeholder="请输入内存信息"></el-input>
	  </el-form-item>
	  <el-form-item v-if="editForm.current_link=='待开通'" label="存储" prop="storage">
	  	<el-input v-model="editForm.storage" placeholder="请输入存储信息"></el-input>
	  </el-form-item>
	  <el-form-item v-if="editForm.current_link=='待开通'" label="上架位置" prop="on_location">
	  	<el-input v-model="editForm.on_location" placeholder="请输入上架位置"></el-input>
	  </el-form-item>
	  <el-form-item v-if="editForm.current_link=='待开通'" label="网络IP(掩码/IP)" prop="network_ip">
	  	<el-input v-model="editForm.network_ip" placeholder="请输入开通IP相关信息"></el-input>
	  </el-form-item>

						
			<el-tag>处理意见</el-tag>			
			<el-form-item v-if="editForm.current_link=='待审批'" label="审批意见" prop="approve">
				<el-select v-model="editForm.approve" placeholder="请选择审批意见">
				  <el-option label="同意" value="同意"></el-option>
				  <el-option label="不同意" value="不同意"></el-option>
				</el-select>
			</el-form-item>
			<el-form-item v-else-if="editForm.current_link=='待开通'" label="开通情况" prop="approve">
				<el-select v-model="editForm.approve" placeholder="请选择开通情况">
				  <el-option label="已开通" value="已开通"></el-option>
				  <el-option label="未开通" value="未开通"></el-option>
				</el-select>
			</el-form-item>
			<el-form-item v-else="editForm.current_link=='待验收'" label="验收意见" prop="approve">
				<el-select v-model="editForm.approve" placeholder="请选择验收意见">
				  <el-option label="同意验收" value="同意验收"></el-option>
				  <el-option label="不同意验收" value="不同意验收"></el-option>
				</el-select>
			</el-form-item> 		
   </el-form>
   <div slot="footer" class="dialog-footer">
    <el-button @click.native="handleCancel()">取消</el-button>
    <el-button v-if="editForm.current_link=='待审批'" type="primary" @click.native="handleApproval()">审批同意</el-button>
    <el-button v-else-if="editForm.current_link=='待开通'" type="primary" @click.native="handleOpen()">确认竣工</el-button>
    <el-button v-else="editForm.current_link=='待验收'" type="primary" @click.native="handleCheck()">同意验收</el-button>
   </div>
  </el-dialog>
</div>
</template>

<script>
import axios from 'axios'
export default {
  name:'ApprovalEquipmentSubmitForm',
  data(){
	  
    return{
	  approve:'',
      visible:this.approvalEquipmentSubmitFormShow,
      editForm:this.approvalEquipmentSubmitForm
    }
  },
 
  watch: {
    visible(){
      this.visible = this.approvalEquipmentSubmitFormShow;
    }
  },
  props: {
    approvalEquipmentSubmitFormShow: {
      type: Boolean,
      default: false
    },
    approvalEquipmentSubmitForm: {
      type: Object,
      default:{}
    }
  },
  mounted(){
    // console.log(this.editForm)
    // console.log(this.editBreakForm)
  },
  methods: {
    handleCancel(){
      this.$emit('update:approvalEquipmentSubmitFormShow', false)
    },
    handleApproval(){
			let name = localStorage.getItem('cur_username')
		  axios
        .get('/api/approval_equipment/',{
					params:{		
						squence:this.editForm.squence,
						process:this.editForm.process,
						name:name,
					},
				})
        .then((res) =>{
					if(res.data.code==200){
						this.$message({
							message: '审批成功！',
							type: 'success'
						})
					}else if(res.data.code==404){
						this.$message({
							message: '未找到记录！',
							type: 'warning'
						})
					}else if(res.data.code==500){
						this.$message({
							message: '数据库错误！',
							type: 'error'
						})
					}else{
						this.$message({
							message: '未知错误！',
							type: 'error'
						})
					}
        })
        .catch((error)=>{
          console.log(error);
        })
			//触发父组件的getData方法,更新表格数据
			this.$emit('getData')
      //更新父组件的表单显示参数，隐藏表单
      this.$emit('update:approvalEquipmentSubmitFormShow', false)
    },
		handleOpen(){
			let name = localStorage.getItem('cur_username')
		  axios
        .get('/api/open_equipment/',{
					params:{
						squence:this.editForm.squence,
						process:this.editForm.process,
						name:name,
					},
				})
        .then((res) =>{
					if(res.data.code==200){
						this.$message({
							message: '开通成功！',
							type: 'success'
						})
					}else if(res.data.code==404){
						this.$message({
							message: '未找到记录！',
							type: 'warning'
						})
					}else if(res.data.code==500){
						this.$message({
							message: '数据库错误！',
							type: 'error'
						})
					}else{
						this.$message({
							message: '未知错误！',
							type: 'error'
						})
					}
        })
		    .catch((error)=>{
		      console.log(error);
		    })
			//触发父组件的getData方法,更新表格数据
			this.$emit('getData')
		  //更新父组件的表单显示参数，隐藏表单
		  this.$emit('update:approvalEquipmentSubmitFormShow', false)
		},
		handleCheck(){
			let name = localStorage.getItem('cur_username')
		  axios
        .get('/api/check_equipment/',{
					params:{
						squence:this.editForm.squence,
						process:this.editForm.process,
						name:name,
					},
				})
        .then((res) =>{
					if(res.data.code==200){
						this.$message({
							message: '验收成功！',
							type: 'success'
						})
					}else if(res.data.code==404){
						this.$message({
							message: '未找到记录！',
							type: 'warning'
						})
					}else if(res.data.code==500){
						this.$message({
							message: '数据库错误！',
							type: 'error'
						})
					}else{
						this.$message({
							message: '未知错误！',
							type: 'error'
						})
					}
        })
		    .catch((error)=>{
		      console.log(error);
		    })
			//触发父组件的getData方法,更新表格数据
			this.$emit('getData')
		  //更新父组件的表单显示参数，隐藏表单
		  this.$emit('update:approvalEquipmentSubmitFormShow', false)
		},
  },
}
</script>

<style>
</style>

